package org.example.service.impl;

import org.example.dao.EquipmentDao;
import org.example.entity.Equipment;
import org.example.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author CoderXshuai
 * @date 2020/9/3/0003 14:46
 */
@Service
public class EquipmentServiceImpl implements EquipmentService {
    @Autowired
    private EquipmentDao equipmentDao;

    @Override
    public void insertEquipment(Equipment equipment) {
        equipmentDao.save(equipment);
    }

    @Override
    public void deleteEquipment(Integer eid) {
        equipmentDao.deleteById(eid);
    }

    @Override
    public void updateEquipment(Equipment equipment) {
        equipmentDao.save(equipment);
    }

    @Override
    public List<Equipment> findAllEquipment() {
        Iterable<Equipment> equipmentIterable = equipmentDao.findAll();
        List<Equipment> equipmentList = new ArrayList<>();
        equipmentIterable.forEach(equipmentList::add);
        return equipmentList;
    }

    @Override
    public List<Equipment> findAllByLid(Integer lid) {
        return equipmentDao.findByLocation_Lid(lid);
    }

}
